<template>
    <div class="mainDiv" style="padding: 20px;box-sizing: border-box;">
        <div class="rowHead">
            <el-button type="success" @click="addshop" icon="plus" v-if="isadd">分店总管理员</el-button>
        </div>
        <el-table :data="tlist" height="100%">
            <el-table-column type="index" label="#"></el-table-column>
            <el-table-column prop="username" label="登录账号"></el-table-column>
            <el-table-column prop="name" label="姓名"></el-table-column>
            <el-table-column prop="gradeid" label="权限等级"></el-table-column>
            <el-table-column prop="remarks" label="权限描述"></el-table-column>
            <el-table-column label="设置">
                <template scope="scope">
                    <el-button @click="edit(scope.row)" icon="edit" type="warning" size="small">编辑</el-button>
                </template>
            </el-table-column>
        </el-table>
    </div>
</template>
<script>
import C from '#/src/common/common.js'
export default {
    name: 'adminList',
    data() {
        return {
            tlist: [],
            shopid: ''
        }
    },
    computed: {
        isadd() {
            if (this.tlist.length) {
                return false
            } else {
                return true
            }
        }
    },
    mounted() {
        this.shopid = C.getDatas().shopid
        this.getlist()
    },
    methods: {
        async addshop() {
            let res = await C.openBrowserWindow('/addShopAdmin', { shopid: this.shopid }, {
                transparent: true,
                frame: false,
                width: 400,
                height: 300,
                useSpa: true,
                spaModel: 'organization'
            })
            if (res) {
                C.success(res.data)
                this.getlist()
            }
        },
        async edit(row) {
            let res = await C.openBrowserWindow('/addShopAdmin', { row: row }, {
                transparent: true,
                frame: false,
                width: 400,
                height: 300,
                useSpa: true,
                spaModel: 'organization'
            })
            if (res) {
                C.success(res.data)
                this.getlist()
            }
        },
        close() {
            C.closewin()
        },
        async getlist() {
            let data = await C.ajax('/organization/shop/adminlist', { shopid: this.shopid }, 'post')
            if (data) this.tlist = data
        }
    }
}
</script>